package cn.aylog.test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import org.junit.Test;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

public class EhDemo {

    @Test
    public void run() throws JsonProcessingException {
//        System.out.println(System.getProperty("java.io.tmpdir")); // C:\Users\Angelly\AppData\Local\Temp\
        InputStream is = EhDemo.class.getClassLoader().getResourceAsStream("ehcache.xml");
        CacheManager manager = new CacheManager(is);
        Cache cache = manager.getCache("cacheTest");
        Map<String,String> map = new HashMap<>();
        map.put("a","a");
        map.put("b", "\u00aa");
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(map);
        Element element = new Element("zhangsan",json);
        cache.put(element);
        Element element1 = cache.get("zhangsan");
        System.out.println(element1);
    }
}
